package com.me {
	import com.me.components.MapResource;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.utils.Dictionary;
	import flash.utils.getTimer;
	
	import spark.core.SpriteVisualElement;

	/**
	 *
	 * @author yw
	 *
	 * @Date 2011-9-16 下午04:32:05
	 */
	public class AvatarLayer extends SpriteVisualElement {
		private var _dic:Dictionary = new Dictionary();
		private var _renderTime:Number;

		public function AvatarLayer() {
			super();
			this.mouseChildren = this.mouseEnabled = true;
//			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}

		private function enterFrameHandler(e:Event):void {
			var delta:Number = getTimer() - _renderTime;
			_renderTime = getTimer();
			for (var key:Object in _dic) {
				_dic[key].pass(delta);
			}
		}
		
		override public function addChild(child:DisplayObject):DisplayObject {
			var key:String = (child as MapResource).attatchment.img;
			_dic[key] = child;
			return super.addChild(child);
		}

		public function containsRes(key:String):MapResource {
			return _dic[key];
		}

		public function clear():void {
			while (numChildren > 0) {
				removeChildAt(0);
			}
		}
	}
}
